//
//  GMainViewController.m
//  helpinrain
//
//  Created by Gang.Wang on 12-7-26.
//  Copyright (c) 2012年 Zhuhai Yuike Technology Co., Ltd. All rights reserved.
//

#import "GMainViewController.h"
#import "GMainView.h"
#import "mcf.h"

@interface GMainViewController ()
{
    GMainView * mainView_;
}

@property (nonatomic, strong) GMainView * mainView;

@end

@implementation GMainViewController
@synthesize mainView = mainView_;

- (void) dealloc
{
     YRelease(mainView_)   
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(CGRect) thisFullRect {
    if ([YkSystem isLayoutPortrait]) 
    {
        if (isPad) 
        {
            return CGRectMake(0, 0, 768, 1004);
        }
        else if(isPhone5)
        {
            return CGRectMake(0, 0, 320, 546);
        }
        else
        {
            return CGRectMake(0, 0, 320, 460);
        }
        
    }
    else
    {
        if (isPad) 
        {
            return CGRectMake(0, 0, 1024, 748);
        }
        else if (isPhone5)
        {
            return CGRectMake(0, 0, 566, 300);
        }
        else
        {
            return CGRectMake(0, 0, 480, 300);
        }       
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    CGRect frame = [self thisFullRect];
    
    GMainView * temp_mainView = [[GMainView alloc] initWithFrame:frame];
    [temp_mainView setBackgroundColor:RGB(74, 82, 89)];
    self.mainView = temp_mainView;
    YRelease(temp_mainView)
    
    [self.view addSubview:self.mainView];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return FALSE;
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void) rotateViewControll:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    @autoreleasepool {        
        CGRect rect;
        if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
           toInterfaceOrientation == UIInterfaceOrientationLandscapeRight )
        {
            
            if (isPad) 
            {
                rect = CGRectMake(0, 0, 1024, 748);
            }
            else 
            {
                rect = CGRectMake(0, 0, 690, 460);
            } 
        }
        else
        {    
            if (isPad) 
            {
                rect = CGRectMake(0, 0, 768, 1004);
            }
            else 
            {
                rect = CGRectMake(0, 0, 480, 670);
            }


        }
        
        
        [[YkAnimationStep for:0.4 animate:^{
            [self.mainView setFrame:rect];
        }] runAnimation];// run
        
        
        [self.mainView rotate:toInterfaceOrientation 
                 includeSubViews:YES 
                       animation:YES];       
    }    
}



- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [self rotateViewControll:toInterfaceOrientation duration:duration];
}


@end
